<template>
  <div>
    <input
      type="text"
      v-model="todoName"
      @keyup.enter="addTodo"
    />
  </div>
</template>

<script setup lang="ts">
import { ref   } from 'vue'
import { useStore } from 'vuex'
import { key } from '../store'
import { useRouter } from 'vue-router';

const store = useStore(key)
const router = useRouter()

const todoName = ref('')
const addTodo = (): void => {
  store.dispatch('todos/addTodo',todoName.value )
  todoName.value = ''
  // 跳转回列表页面
  router.push('/')
}
</script>

<style lang="scss" scoped></style>
